import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/house/house_list.dart';
import 'package:flutter_enjoy_plus/pages/house/location_list.dart';
import 'package:flutter_enjoy_plus/pages/house/room_list.dart';
import 'package:flutter_enjoy_plus/pages/login/index.dart';
import 'package:flutter_enjoy_plus/pages/notFound/index.dart';
import 'package:flutter_enjoy_plus/pages/notice/index.dart';
import 'package:flutter_enjoy_plus/pages/profile/index.dart';
import 'package:flutter_enjoy_plus/pages/tab_bar_page.dart';
import 'package:flutter_enjoy_plus/utils/token.dart';

class RouteManager {
  static Map<String, WidgetBuilder> routes = {
    '/': (context) => const TabBarPage(),
    '/detail': (context) => const NoticeDetail(),
    '/login': (context) => const LoginPage()
  };
  static Route<dynamic> generateRoute (RouteSettings settings) {
    final token = TokenManager().getToken() ?? '';
    if (token.isEmpty && settings.name != '/login') {
      return MaterialPageRoute(builder: (context) => const LoginPage());
    }
    if (settings.name == '/profile') {
      return MaterialPageRoute(
          builder: (context) =>
              ProfilePage(userInfo: settings.arguments as Map));
    }
    if (settings.name == '/house_list') {
      return MaterialPageRoute(builder: (context) => const HouseList());
    }
    if (settings.name == '/location_list') {
      return MaterialPageRoute(builder: (context) => const LocationList());
    }
    if (settings.name == '/room_list') {
      return MaterialPageRoute(
          builder: (context) =>
              BuildingList(point: (settings.arguments as Map)['point']));
    }
    return MaterialPageRoute(builder: (context) => const NotFound());
  }
}
